package edu.pku.sei.modeler.editparts;

import java.beans.PropertyChangeEvent;

import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.editpolicies.DirectEditPolicy;
import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gef.tools.DragEditPartsTracker;

import edu.pku.sei.modeler.editpolicies.SequenceNodeEditPolicy;
import edu.pku.sei.modeler.figures.StopFigure;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.structure.MetaShapeElement;
import edu.pku.sei.modeler.model.uml.BasicInteractions.DestructionEvent;

public class DestructionEventEditpart extends AbstractUMLNodeEditPart {

	public DestructionEventEditpart(MetaShapeElement model) {
		super(model);
	}

	
	private DestructionEvent getModelElement() {
		return (DestructionEvent) ((MetaNode)this.getModel()).getModelElement();
	}
	

	@Override
	protected DirectEditPolicy createDirectEditPolicy() {
		return null;
	}

	@Override
	protected IFigure createFigure() {
		return new StopFigure();
	}

	
	
	
	
	@Override
	protected void handlePropertyChanged(PropertyChangeEvent event) {
		refreshVisuals();
		super.handlePropertyChanged(event);
	}


	@Override
	protected void refreshVisuals() {
		super.refreshVisuals();
	}

	@Override
	protected void createEditPolicies() {
		super.createEditPolicies();
		installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new SequenceNodeEditPolicy());
	}

	@Override
	public DragTracker getDragTracker(Request request) {
		return new DragEditPartsTracker(this) {
			@Override
			protected void updateTargetRequest() {
				super.updateTargetRequest();
				ChangeBoundsRequest request = (ChangeBoundsRequest)getTargetRequest();
				request.getMoveDelta().x = 0;
				request.getMoveDelta().y = 0;
			}
		};
	}
	
	
	
}
